<?php
use yii\helpers\Html;
?>
<table class="table table-hover">
	<thead>
		<tr>
			<th>#</th>
			<th>游戏名成</th>
			<th>拼音</th>
			<th>状态</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
		<?php foreach ($data as $item):?>
		<tr>
			<td><?= $item['game_id'];?></td>
			<td><?= truncate(Html::encode($item['game_name']),23);?></td>
			<td><?= truncate(Html::encode($item['pinyin']),13);?></td>
			<td><?= Html::encode($item['state_name']);?></td>
			<td>
				<a class="btn btn-sm btn-warning" href="javascript:void(0)" onclick="assignGame(<?= $item['game_id'];?>, <?= $game_notice_id;?>)"><i class="icon-login"></i> 指派</a>
			</td>
		</tr>
		<?php endforeach;?>
	</tbody>
</table>
<script type="text/javascript">
//指派确认
function assignGame(game_id, game_notice_id){
	var obj=$(this);
	var csrfToken = $('meta[name="csrf-token"]').attr("content");
	if( game_id > 0 && game_notice_id>0){
		$.ajax({
			type: 'POST',
	        url: "<?php echo \Yii::$app->urlManager->createUrl('/game-notice/assign-game');?>",
	        data: { game_id : game_id, game_notice_id : game_notice_id, _csrf : csrfToken },
	        dataType: 'json',
	        success: function(data) {
	        	alert("指派成功");
	        }
	    });
	}else{
		alert("参数错误！游戏公告ID和被指派的游戏ID不能为空");
	}
}
</script>